home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MOR55SRC.ZIP / MORIA / SOURCE / SCROLLS.C < prev    next >
C/C++ Source or Header  |  1992-12-07  |  14KB  |  530 lines

  1. /* source/scrolls.c: scroll code
  2.  
  3.    Copyright (c) 1989-92 James E. Wilson, Robert A. Koeneke
  4.  
  5.    This software may be copied and distributed for educational, research, and
  6.    not for profit purposes provided that this copyright and statement are
  7.    included in all such copies. */
  8.  
  9. #ifdef __TURBOC__
  10. #include    <stdio.h>
  11. #endif /* __TURBOC__ */
  12.  
  13. #include "config.h"
  14. #include "constant.h"
  15. #include "types.h"
  16. #include "externs.h"
  17.  
  18. #ifdef USG
  19. #include <string.h>
  20. #else
  21. #include <strings.h>
  22. #endif
  23.  
  24. /* Scrolls for the reading                -RAK-    */
  25. void read_scroll()
  26. {
  27.   int32u i;
  28.   int j, k, item_val, y, x;
  29.   int tmp[6], flag, used_up;
  30.   bigvtype out_val, tmp_str;
  31.   register int ident, l;
  32.   register inven_type *i_ptr;
  33.   register struct misc *m_ptr;
  34. #ifdef ATARIST_MWC
  35.   int32u holder = TR_CURSED;
  36. #endif
  37.  
  38.   free_turn_flag = TRUE;
  39.   if (py.flags.blind > 0)
  40.     msg_print("You can't see to read the scroll.");
  41.   else if (no_light())
  42.     msg_print("You have no light to read by.");
  43.   else if (py.flags.confused > 0)
  44.     msg_print("You are too confused to read a scroll.");
  45.   else if (inven_ctr == 0)
  46.     msg_print("You are not carrying anything!");
  47.   else if (!find_range(TV_SCROLL1, TV_SCROLL2, &j, &k))
  48.     msg_print ("You are not carrying any scrolls!");
  49.   else if (get_item(&item_val, "Read which scroll?", j, k, CNIL, CNIL))
  50.     {
  51.       i_ptr = &inventory[item_val];
  52.       free_turn_flag = FALSE;
  53.       used_up = TRUE;
  54.       i = i_ptr->flags;
  55.       ident = FALSE;
  56.  
  57.       while (i != 0)
  58.     {
  59.       j = bit_pos(&i) + 1;
  60.       if (i_ptr->tval == TV_SCROLL2)
  61.         j += 32;
  62.  
  63.       /* Scrolls.            */
  64.       switch(j)
  65.         {
  66.         case 1:
  67.           i_ptr = &inventory[INVEN_WIELD];
  68.           if (i_ptr->tval != TV_NOTHING)
  69.         {
  70.           objdes(tmp_str, i_ptr, FALSE);
  71.           (void) sprintf(out_val, "Your %s glows faintly!", tmp_str);
  72.           msg_print(out_val);
  73.           if (enchant(&i_ptr->tohit, 10))
  74.             {
  75. #ifdef ATARIST_MWC
  76.               i_ptr->flags &= ~holder;
  77. #else
  78.               i_ptr->flags &= ~TR_CURSED;
  79. #endif
  80.               calc_bonuses();
  81.             }
  82.           else
  83.             msg_print("The enchantment fails.");
  84.           ident = TRUE;
  85.         }
  86.           break;
  87.         case 2:
  88.           i_ptr = &inventory[INVEN_WIELD];
  89.           if (i_ptr->tval != TV_NOTHING)
  90.         {
  91.           objdes(tmp_str, i_ptr, FALSE);
  92.           (void) sprintf(out_val, "Your %s glows faintly!", tmp_str);
  93.           msg_print(out_val);
  94.           if ((i_ptr->tval >= TV_HAFTED)&&(i_ptr->tval <= TV_DIGGING))
  95.             j = i_ptr->damage[0] * i_ptr->damage[1];
  96.           else /* Bows' and arrows' enchantments should not be limited
  97.               by their low base damages */
  98.             j = 10; 
  99.           if (enchant(&i_ptr->todam, j))
  100.             {
  101. #ifdef ATARIST_MWC
  102.               i_ptr->flags &= ~holder;
  103. #else
  104.               i_ptr->flags &= ~TR_CURSED;
  105. #endif
  106.               calc_bonuses ();
  107.             }
  108.           else
  109.             msg_print("The enchantment fails.");
  110.           ident = TRUE;
  111.         }
  112.           break;
  113.         case 3:
  114.           k = 0;
  115.           l = 0;
  116.           if (inventory[INVEN_BODY].tval != TV_NOTHING)
  117.         tmp[k++] = INVEN_BODY;
  118.           if (inventory[INVEN_ARM].tval != TV_NOTHING)
  119.         tmp[k++] = INVEN_ARM;
  120.           if (inventory[INVEN_OUTER].tval != TV_NOTHING)
  121.         tmp[k++] = INVEN_OUTER;
  122.           if (inventory[INVEN_HANDS].tval != TV_NOTHING)
  123.         tmp[k++] = INVEN_HANDS;
  124.           if (inventory[INVEN_HEAD].tval != TV_NOTHING)
  125.         tmp[k++] = INVEN_HEAD;
  126.           /* also enchant boots */
  127.           if (inventory[INVEN_FEET].tval != TV_NOTHING)
  128.         tmp[k++] = INVEN_FEET;
  129.  
  130.           if (k > 0)  l = tmp[randint(k)-1];
  131. #ifdef ATARIST_MWC
  132.           if (holder & inventory[INVEN_BODY].flags)
  133.         l = INVEN_BODY;
  134.           else if (holder & inventory[INVEN_ARM].flags)
  135.         l = INVEN_ARM;
  136.           else if (holder & inventory[INVEN_OUTER].flags)
  137.         l = INVEN_OUTER;
  138.           else if (holder & inventory[INVEN_HEAD].flags)
  139.         l = INVEN_HEAD;
  140.           else if (holder & inventory[INVEN_HANDS].flags)
  141.         l = INVEN_HANDS;
  142.           else if (holder & inventory[INVEN_FEET].flags)
  143.         l = INVEN_FEET;
  144. #else
  145.           if (TR_CURSED & inventory[INVEN_BODY].flags)
  146.         l = INVEN_BODY;
  147.           else if (TR_CURSED & inventory[INVEN_ARM].flags)
  148.         l = INVEN_ARM;
  149.           else if (TR_CURSED & inventory[INVEN_OUTER].flags)
  150.         l = INVEN_OUTER;
  151.           else if (TR_CURSED & inventory[INVEN_HEAD].flags)
  152.         l = INVEN_HEAD;
  153.           else if (TR_CURSED & inventory[INVEN_HANDS].flags)
  154.         l = INVEN_HANDS;
  155.           else if (TR_CURSED & inventory[INVEN_FEET].flags)
  156.         l = INVEN_FEET;
  157. #endif
  158.  
  159.           if (l > 0)
  160.         {
  161.           i_ptr = &inventory[l];
  162.           objdes(tmp_str, i_ptr, FALSE);
  163.           (void) sprintf(out_val, "Your %s glows faintly!", tmp_str);
  164.           msg_print(out_val);
  165.           if (enchant(&i_ptr->toac, 10))
  166.             {
  167. #ifdef ATARIST_MWC
  168.               i_ptr->flags &= ~holder;
  169. #else
  170.               i_ptr->flags &= ~TR_CURSED;
  171. #endif
  172.               calc_bonuses ();
  173.             }
  174.           else
  175.             msg_print("The enchantment fails.");
  176.           ident = TRUE;
  177.         }
  178.           break;
  179.         case 4:
  180.           msg_print("This is an identify scroll.");
  181.           ident = TRUE;
  182.           used_up = ident_spell();
  183.  
  184.           /* The identify may merge objects, causing the identify scroll
  185.          to move to a different place.    Check for that here.  It can
  186.          move arbitrarily far if an identify scroll was used on
  187.          another identify scroll, but it always moves down. */
  188.           while (i_ptr->tval != TV_SCROLL1 || i_ptr->flags != 0x00000008)
  189.         {
  190.           item_val--;
  191.           i_ptr = &inventory[item_val];
  192.         }
  193.           break;
  194.         case 5:
  195.           if (remove_curse())
  196.         {
  197.           msg_print("You feel as if someone is watching over you.");
  198.           ident = TRUE;
  199.         }
  200.           break;
  201.         case 6:
  202.           ident = light_area(char_row, char_col);
  203.           break;
  204.         case 7:
  205.           for (k = 0; k < randint(3); k++)
  206.         {
  207.           y = char_row;
  208.           x = char_col;
  209.           ident |= summon_monster(&y, &x, FALSE);
  210.         }
  211.           break;
  212.         case 8:
  213.           teleport(10);
  214.           ident = TRUE;
  215.           break;
  216.         case 9:
  217.           teleport(100);
  218.           ident = TRUE;
  219.           break;
  220.         case 10:
  221.           dun_level += (-3) + 2*randint(2);
  222.           if (dun_level < 1)
  223.         dun_level = 1;
  224.           new_level_flag = TRUE;
  225.           ident = TRUE;
  226.           break;
  227.         case 11:
  228.           if (py.flags.confuse_monster == 0)
  229.         {
  230.           msg_print("Your hands begin to glow.");
  231.           py.flags.confuse_monster = TRUE;
  232.           ident = TRUE;
  233.         }
  234.           break;
  235.         case 12:
  236.           ident = TRUE;
  237.           map_area();
  238.           break;
  239.         case 13:
  240.           ident = sleep_monsters1(char_row, char_col);
  241.           break;
  242.         case 14:
  243.           ident = TRUE;
  244.           warding_glyph();
  245.           break;
  246.         case 15:
  247.           ident = detect_treasure();
  248.           break;
  249.         case 16:
  250.           ident = detect_object();
  251.           break;
  252.         case 17:
  253.           ident = detect_trap();
  254.           break;
  255.         case 18:
  256.           ident = detect_sdoor();
  257.           break;
  258.         case 19:
  259.           msg_print("This is a mass genocide scroll.");
  260.           ident = mass_genocide();
  261.           break;
  262.         case 20:
  263.           ident = detect_invisible();
  264.           break;
  265.         case 21:
  266.           ident = aggravate_monster(20);
  267.           if (ident)
  268.         msg_print("There is a high pitched humming noise.");
  269.           break;
  270.         case 22:
  271.           ident = trap_creation();
  272.           break;
  273.         case 23:
  274.           ident = td_destroy();
  275.           break;
  276.         case 24:
  277.           ident = door_creation();
  278.           break;
  279.         case 25:
  280.           msg_print("This is a Recharge-Item scroll.");
  281.           ident = TRUE;
  282.           used_up = recharge(60);
  283.           break;
  284.         case 26:
  285.           msg_print("This is a genocide scroll.");
  286.           ident = genocide();
  287.           break;
  288.         case 27:
  289.           ident = unlight_area(char_row, char_col);
  290.           break;
  291.         case 28:
  292.           ident = protect_evil();
  293.           break;
  294.         case 29:
  295.           ident = TRUE;
  296.           create_food();
  297.           break;
  298.         case 30:
  299.           ident = dispel_creature(CD_UNDEAD, 60);
  300.           break;
  301.         case 33:
  302.           i_ptr = &inventory[INVEN_WIELD];
  303.           if (i_ptr->tval != TV_NOTHING)
  304.         {
  305.           objdes(tmp_str, i_ptr, FALSE);
  306.           (void) sprintf(out_val, "Your %s glows brightly!", tmp_str);
  307.           msg_print(out_val);
  308.           flag = FALSE;
  309.           for (k = 0; k < randint(2); k++)
  310.             if (enchant(&i_ptr->tohit, 10))
  311.               flag = TRUE;
  312.           if ((i_ptr->tval >= TV_HAFTED)&&(i_ptr->tval <= TV_DIGGING))
  313.             j = i_ptr->damage[0] * i_ptr->damage[1];
  314.           else /* Bows' and arrows' enchantments should not be limited
  315.               by their low base damages */
  316.             j = 10; 
  317.           for (k = 0; k < randint(2); k++)
  318.             if (enchant(&i_ptr->todam, j))
  319.               flag = TRUE;
  320.           if (flag)
  321.             {
  322. #ifdef ATARIST_MWC
  323.               i_ptr->flags &= ~holder;
  324. #else
  325.               i_ptr->flags &= ~TR_CURSED;
  326. #endif
  327.               calc_bonuses ();
  328.             }
  329.           else
  330.             msg_print("The enchantment fails.");
  331.           ident = TRUE;
  332.         }
  333.           break;
  334.         case 34:
  335.           i_ptr = &inventory[INVEN_WIELD];
  336.           if (i_ptr->tval != TV_NOTHING)
  337.         {
  338.           objdes(tmp_str, i_ptr, FALSE);
  339.           (void)sprintf(out_val,"Your %s glows black, fades.",tmp_str);
  340.           msg_print(out_val);
  341.           unmagic_name(i_ptr);
  342.           i_ptr->tohit = -randint(5) - randint(5);
  343.           i_ptr->todam = -randint(5) - randint(5);
  344.           /* Must call py_bonuses() before set (clear) flags, and
  345.              must call calc_bonuses() after set (clear) flags, so that
  346.              all attributes will be properly turned off. */
  347.           py_bonuses(i_ptr, -1);
  348.           i_ptr->flags = TR_CURSED;
  349.           calc_bonuses ();
  350.           ident = TRUE;
  351.         }
  352.           break;
  353.         case 35:
  354.           k = 0;
  355.           l = 0;
  356.           if (inventory[INVEN_BODY].tval != TV_NOTHING)
  357.         tmp[k++] = INVEN_BODY;
  358.           if (inventory[INVEN_ARM].tval != TV_NOTHING)
  359.         tmp[k++] = INVEN_ARM;
  360.           if (inventory[INVEN_OUTER].tval != TV_NOTHING)
  361.         tmp[k++] = INVEN_OUTER;
  362.           if (inventory[INVEN_HANDS].tval != TV_NOTHING)
  363.         tmp[k++] = INVEN_HANDS;
  364.           if (inventory[INVEN_HEAD].tval != TV_NOTHING)
  365.         tmp[k++] = INVEN_HEAD;
  366.           /* also enchant boots */
  367.           if (inventory[INVEN_FEET].tval != TV_NOTHING)
  368.         tmp[k++] = INVEN_FEET;
  369.  
  370.           if (k > 0)  l = tmp[randint(k)-1];
  371. #ifdef ATARIST_MWC
  372.           if (holder & inventory[INVEN_BODY].flags)
  373.         l = INVEN_BODY;
  374.           else if (holder & inventory[INVEN_ARM].flags)
  375.         l = INVEN_ARM;
  376.           else if (holder & inventory[INVEN_OUTER].flags)
  377.         l = INVEN_OUTER;
  378.           else if (holder & inventory[INVEN_HEAD].flags)
  379.         l = INVEN_HEAD;
  380.           else if (holder & inventory[INVEN_HANDS].flags)
  381.         l = INVEN_HANDS;
  382.           else if (holder & inventory[INVEN_FEET].flags)
  383.         l = INVEN_FEET;
  384. #else
  385.           if (TR_CURSED & inventory[INVEN_BODY].flags)
  386.         l = INVEN_BODY;
  387.           else if (TR_CURSED & inventory[INVEN_ARM].flags)
  388.         l = INVEN_ARM;
  389.           else if (TR_CURSED & inventory[INVEN_OUTER].flags)
  390.         l = INVEN_OUTER;
  391.           else if (TR_CURSED & inventory[INVEN_HEAD].flags)
  392.         l = INVEN_HEAD;
  393.           else if (TR_CURSED & inventory[INVEN_HANDS].flags)
  394.         l = INVEN_HANDS;
  395.           else if (TR_CURSED & inventory[INVEN_FEET].flags)
  396.         l = INVEN_FEET;
  397. #endif
  398.  
  399.           if (l > 0)
  400.         {
  401.           i_ptr = &inventory[l];
  402.           objdes(tmp_str, i_ptr, FALSE);
  403.           (void) sprintf(out_val,"Your %s glows brightly!", tmp_str);
  404.           msg_print(out_val);
  405.           flag = FALSE;
  406.           for (k = 0; k < randint(2) + 1; k++)
  407.             if (enchant(&i_ptr->toac, 10))
  408.               flag = TRUE;
  409.           if (flag)
  410.             {
  411. #ifdef ATARIST_MWC
  412.               i_ptr->flags &= ~holder;
  413. #else
  414.               i_ptr->flags &= ~TR_CURSED;
  415. #endif
  416.               calc_bonuses ();
  417.             }
  418.           else
  419.             msg_print("The enchantment fails.");
  420.           ident = TRUE;
  421.         }
  422.           break;
  423.         case 36:
  424.           if ((inventory[INVEN_BODY].tval != TV_NOTHING)
  425.           && (randint(4) == 1))
  426.         k = INVEN_BODY;
  427.           else if ((inventory[INVEN_ARM].tval != TV_NOTHING)
  428.                && (randint(3) ==1))
  429.         k = INVEN_ARM;
  430.           else if ((inventory[INVEN_OUTER].tval != TV_NOTHING)
  431.                && (randint(3) ==1))
  432.         k = INVEN_OUTER;
  433.           else if ((inventory[INVEN_HEAD].tval != TV_NOTHING)
  434.                && (randint(3) ==1))
  435.         k = INVEN_HEAD;
  436.           else if ((inventory[INVEN_HANDS].tval != TV_NOTHING)
  437.                && (randint(3) ==1))
  438.         k = INVEN_HANDS;
  439.           else if ((inventory[INVEN_FEET].tval != TV_NOTHING)
  440.                && (randint(3) ==1))
  441.         k = INVEN_FEET;
  442.           else if (inventory[INVEN_BODY].tval != TV_NOTHING)
  443.         k = INVEN_BODY;
  444.           else if (inventory[INVEN_ARM].tval != TV_NOTHING)
  445.         k = INVEN_ARM;
  446.           else if (inventory[INVEN_OUTER].tval != TV_NOTHING)
  447.         k = INVEN_OUTER;
  448.           else if (inventory[INVEN_HEAD].tval != TV_NOTHING)
  449.         k = INVEN_HEAD;
  450.           else if (inventory[INVEN_HANDS].tval != TV_NOTHING)
  451.         k = INVEN_HANDS;
  452.           else if (inventory[INVEN_FEET].tval != TV_NOTHING)
  453.         k = INVEN_FEET;
  454.           else
  455.         k = 0;
  456.  
  457.           if (k > 0)
  458.         {
  459.           i_ptr = &inventory[k];
  460.           objdes(tmp_str, i_ptr, FALSE);
  461.           (void)sprintf(out_val,"Your %s glows black, fades.",tmp_str);
  462.           msg_print(out_val);
  463.           unmagic_name(i_ptr);
  464.           i_ptr->flags = TR_CURSED;
  465.           i_ptr->toac = -randint(5) - randint(5);
  466.           calc_bonuses ();
  467.           ident = TRUE;
  468.         }
  469.           break;
  470.         case 37:
  471.           ident = FALSE;
  472.           for (k = 0; k < randint(3); k++)
  473.         {
  474.           y = char_row;
  475.           x = char_col;
  476.           ident |= summon_undead(&y, &x);
  477.         }
  478.           break;
  479.         case 38:
  480.           ident = TRUE;
  481.           bless(randint(12)+6);
  482.           break;
  483.         case 39:
  484.           ident = TRUE;
  485.           bless(randint(24)+12);
  486.           break;
  487.         case 40:
  488.           ident = TRUE;
  489.           bless(randint(48)+24);
  490.           break;
  491.         case 41:
  492.           ident = TRUE;
  493.           if (py.flags.word_recall == 0)
  494.         py.flags.word_recall = 25 + randint(30);
  495.           msg_print("The air about you becomes charged.");
  496.           break;
  497.         case 42:
  498.           destroy_area(char_row, char_col);
  499.           ident = TRUE;
  500.           break;
  501.         default:
  502.           msg_print("Internal error in scroll()");
  503.           break;
  504.         }
  505.       /* End of Scrolls.                   */
  506.     }
  507.       i_ptr = &inventory[item_val];
  508.       if (ident)
  509.     {
  510.       if (!known1_p(i_ptr))
  511.         {
  512.           m_ptr = &py.misc;
  513.           /* round half-way case up */
  514.           m_ptr->exp += (i_ptr->level +(m_ptr->lev >> 1)) / m_ptr->lev;
  515.           prt_experience();
  516.  
  517.           identify(&item_val);
  518.           i_ptr = &inventory[item_val];
  519.         }
  520.     }
  521.       else if (!known1_p(i_ptr))
  522.     sample (i_ptr);
  523.       if (used_up)
  524.     {
  525.       desc_remain(item_val);
  526.       inven_destroy(item_val);
  527.     }
  528.     }
  529. }
  530.